package com.kgc.scd.controller;

import com.kgc.scd.bean.SensitiveWordResult;
import com.kgc.scd.service.SensitiveWordService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: com.kgc.scd.controller
 * @author: HarryXzy
 * @create: 2022-06-14 09:51
 * @description: 敏感词controller
 **/
@RestController
@Api(tags = "03、敏感词操作入口")
public class SensitiveWordController {

    @Autowired
    private SensitiveWordService sensitiveWordService;

    /**
    * @author: HarryXzy
    * @date: 2022/6/14 09:53
    * @return: com.kgc.scd.util.RequestResult<java.lang.String>
    * @description: 获取所有敏感词
    */
    @GetMapping(value = "/allSensitiveWord")
    @ApiOperation(value = "获取所有的敏感词", notes = "获取所有的敏感词，采用分页进行展示")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "请求成功")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数")
    })
    public RequestResult allSensitiveWord(@RequestParam("pageNo") int pageNo,
                                          @RequestParam("pageSize")int pageSize){
        // 获取所有的敏感词
        Map<String, Object> result = sensitiveWordService.allSensitiveWord(pageNo,pageSize);
        if(result.get("code").equals("200")){
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(),(String) result.get("msg"));
    }



    /**
     * @author: HarryXzy
     * @date: 2022/6/14 09:53
     * @return: com.kgc.scd.util.RequestResult<java.lang.String>
     * @description: 删除敏感词
     */
    @DeleteMapping("/deleteSensitiveWord")
    @ApiOperation(value = "删除敏感词", notes = "根据敏感词，删除敏感词")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 503, message = "敏感词不存在"),
            @ApiResponse(code = 200, message = "敏感词删除成功")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sensitiveWord", value = "敏感词")
    })
    public RequestResult deleteSensitiveWord(@RequestParam("sensitiveWord")String sensitiveWord){
        HashMap<String, Object> map = new HashMap<>();
        // 删除敏感词
        Map<String, Object> result = sensitiveWordService.deleteSensitiveWord(sensitiveWord);
        if(result.get("code").equals("200")){
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(),(String) result.get("msg"));
    }

    /**
    * @author: HarryXzy
    * @date: 2022/6/14 10:12
    * @return: java.util.Map<java.lang.String,java.lang.Object>
    * @description: 添加敏感词
    */
    @PostMapping("/addSensitiveWord")
    @ApiOperation(value = "添加敏感词", notes = "添加敏感词")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 503, message = "敏感词已存在"),
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "敏感词添加成功")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "敏感词种类ID"),
            @ApiImplicitParam(name = "sensitiveWord", value = "敏感词")
    })
    public RequestResult addSensitiveWord(@RequestParam("categoryId") String categoryId,
                                          @RequestParam("sensitiveWord")String sensitiveWord) {
        HashMap<String, Object> map = new HashMap<>();
        // 添加敏感词
        Map<String, Object> result = sensitiveWordService.addSensitiveWord(categoryId, sensitiveWord);
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), (String) result.get("msg"));
    }




    /**
     * @author: HarryXzy
     * @date: 2022/6/14 10:12
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     * @description: 获取敏感词种类
     */
    @PostMapping("/sensitiveWordType")
    @ApiOperation(value = "获取敏感词种类", notes = "获取敏感词种类")
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "请求成功")
    })
    public RequestResult getsensitiveWordType(){
        HashMap<String, Object> map = new HashMap<>();
        // 添加敏感词
        Map<String, Object> result = sensitiveWordService.getsensitiveWordType();
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), (String) result.get("msg"));
    }


}
